use std::time::{SystemTime};
use std::rc::Rc;
use std::cell::RefCell;


pub struct CalcTime {
    start_time: SystemTime,
    //end_time: SystemTime,
}

impl CalcTime {
    fn new() -> Rc<RefCell<CalcTime>> {
        return Rc::new(RefCell::new(CalcTime {
            start_time: SystemTime::now(),
            //end_time: SystemTime::now(),
        }));
    }
    pub fn start(&mut self) {
        self.start_time = SystemTime::now();
    }

    pub fn end(&self) -> u128 {
        let mut time = 0;
        SPENT.with(| _f| {
            time = SystemTime::now().duration_since(self.start_time).unwrap().as_millis();
        });
        return time;
    }
}

thread_local!(pub static SPENT: Rc<RefCell<CalcTime>> = CalcTime::new() );